import java.util.Comparator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-02-06
 * Time: 21:22
 */
class Person implements Comparable<Person> {
    public String name;
    public int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Person o) {
        return this.name.compareTo(o.name);
    }
}
class NameComparator implements Comparator<Person>{
    @Override
    public int compare(Person o1, Person o2) {
        return o1.compareTo(o2);
    }
}
class AgeComparator implements Comparator<Person>{

    @Override
    public int compare(Person o1, Person o2) {
        return o1.age-o2.age;
    }
}
public class Test {
    public static void main(String[] args) {
        Person person=new Person("zhangsna",20);
        Person person2=new Person("lisi",10);
        System.out.println(person.compareTo(person2));
        System.out.println("========================");
        NameComparator nameComparator=new NameComparator();
        System.out.println(nameComparator.compare(person, person2));
        System.out.println("===================");
        AgeComparator ageComparator=new AgeComparator();
        System.out.println(ageComparator.compare(person, person2));
    }
}
